package com.kantboot.io.exception;

import com.kantboot.io.util.RestResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;


@ControllerAdvice
public class ControllerExceptionHandler {

    @ExceptionHandler(UpdateException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RestResult<String> handlerUpdateException(UpdateException ex){
        return new RestResult<String>().setState(ex.getId()).setErrMsg(ex.getMessage());
    }

    @ExceptionHandler(CesUserException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RestResult<String> handlerUserException(CesUserException ex){
        return new RestResult<String>().setState(ex.getId()).setErrMsg(ex.getMessage());
    }


    @ExceptionHandler(SessionUtilException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public RestResult<String> handlerException(SessionUtilException ex){
        return new RestResult<String>().setState(ex.getId()).setErrMsg(ex.getMessage());
    }
}
